package com.ellricky.market

import android.app.Activity
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.andr.common.util.StrUtil
import com.ellricky.baselib.util.GlideUtil
import de.hdodenhof.circleimageview.CircleImageView

class MarketIntegralAdapter :
        BaseRecyclerAdapter<MarketIntegralEntity>(R.layout.market_adapter_text) {


    override fun onBindViewHolder(vh: SmartViewHolder?, p1: MarketIntegralEntity?, position: Int) {
        vh?.text(R.id.tvStart, p1?.receiveTime)
        vh?.text(R.id.tvCenter, p1?.scoreFrom)
        vh?.text(R.id.tvEnd, p1?.scoreNum)
    }

}


class MarketActAdapter(val context: Activity) :
        BaseRecyclerAdapter<MarketActEntity>(R.layout.market_adapter_act) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: MarketActEntity?, position: Int) {

        /*val picView = vh?.itemView?.findViewById<ImageView>(R.id.ivEnd)
        picView?.let {
            Glide.with(context).load(p1?.picUrl).into(it)
        }*/

        val title = context.getString(R.string.market_act_adapter_title, p1?.title, p1?.giveScore)
        vh?.text(R.id.tvTitle, title)
        vh?.text(R.id.tvAddr, p1?.address)
        vh?.text(R.id.tvTime, p1?.taskStartDate)
    }

}


class MarketClueBookAdapter(val context: Activity) :
        BaseRecyclerAdapter<MarketCLueEntity>(R.layout.market_adapter_act) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: MarketCLueEntity?, position: Int) {

        val tel = StrUtil.formatPhoneNum(p1?.tel)
        val title = context.getString(R.string.market_clue_adapter_title,
                p1?.name, p1?.sex, p1?.age, tel)
        vh?.text(R.id.tvTitle, title)

        vh?.text(R.id.tvAddr, p1?.fromSchool)
        vh?.text(R.id.tvTime, p1?.clueDate)
    }

}


class MarketRankAdapter(val ctx: Activity) :
        BaseRecyclerAdapter<MarketRankEntity>(R.layout.market_adapter_rank) {

    override fun onBindViewHolder(vh: SmartViewHolder?, model: MarketRankEntity?, position: Int) {
        vh?.text(R.id.tvRankNo, (position + 4).toString())
        vh?.text(R.id.tvUserName, model?.name)
        vh?.text(R.id.tvTotalNum, model?.totalScore)

        val ivAvatar = vh?.itemView?.findViewById<CircleImageView>(R.id.ivAvatar)
        GlideUtil.into(ctx, model?.headPic, ivAvatar)
    }

}
